<template>
	<view class="page" :class="getThemeClass">
		<!-- <view class="" :style="{height: `${navHeight}px`}"></view> -->
		<!-- 登录NFT Marketplace -->
		<!-- <view class="title text-main">{{i18n.login1}}</view> -->
		<!-- 欢迎使用NFT Marketplace -->
		<!-- <view class="title_h1">{{i18n.login2}}</view> -->
		<!-- 头像框 -->
		<view class="text-center">
			<image src="../../../static/images/27.png" mode="" class="Head_image"></image>
		</view>
		<!-- <view class="text-center size-60 u-m-t-20" style="color: #2D3746;">幕图开启AI版权时代</view> -->
		<view class="title_h1">誉言AI</view>
		<view class="input_num border-color">
			<!-- <text @click="openWin('../country/country')">+{{this.$store.state.areacode}}</text> -->
			<!-- 请输入手机号 -->
			<image src="../../../static/images/sjh.png" mode="" class="iconsjh"></image>
			<u-input class="u_input1 text-main" v-model="params.login_account" type="text" :border="false" height="88"
				:placeholder="i18n.login3" :placeholderStyle="`color: ${getTextPlaceholderColor}`" :customStyle="{color: getTextColor}" />
		</view>
		<view class="input_num border-color">
			<image src="../../../static/images/mima.png" mode="" class="iconsjh"></image>
			<u-input class="u_input border-color text-main" v-model="params.password" type="password" :border="false" height="88"
				:placeholder="i18n.login4"  :placeholderStyle="`color: ${getTextPlaceholderColor}`" :customStyle="{color: getTextColor}" />
		</view>
		<view class="fun_flex text-tips">
			<!-- <view @click="openWin('../register/register')">{{i18n.login6}}</view> -->
			<!-- <view @click="openWin('../../my/revise-pwd/revise-pwd')">{{i18n.login8}}</view> -->
			<view @click="openWin('../register/register')">去注册</view>
			<view @click="openWin('../../my/revise-pwd/revise-pwd')">忘记密码？</view>
		</view>
		<!-- 登录 -->
		<botBtn 
			:btnText="i18n.login7" 
			:radius="radius"
			@click="login"
			padding="25rpx 280rpx"
		></botBtn>
		<!-- 忘记密码 -->
		<!-- 第三方授权登录 -->
		<view class="authorize_title">
			<!-- <view class="line line_left"></view>
			{{i18n.login9}}
			<view class="line line_right"></view> -->
		</view>
		<!-- 微博登录 -->
		<!-- <view class="weibo_login">
			<image class="weibo_img" src="../../../static/images/weibo.png" mode="widthFix" @click="weiboLogin"></image>
			
			<view class="weibo_text">{{i18n.login10}}</view>
		</view> -->
		<view class="footer_protocol">
			<image :src="checked?'../../../static/images/check.png':''"
				mode="widthFix" @click="checkedCli()">
			</image>
			<!-- 我已阅读并同意 -->
			<!-- <view class="color_ash text-content">{{i18n.login11}}</view> -->
			<view class="color_ash text-content">勾选代表同意</view>
			<!-- 《用户协议》 -->
			<view class="color_black" @click="openWin('../protocol/protocol')">《{{i18n.login12}}》</view>
			<!-- 和 -->
			<view class="color_ash text-content">{{i18n.login14}}</view>
			<!-- 《隐私政策》 -->
			<view class="color_black" @click="openWin('../policy/policy')">《{{i18n.login13}}》</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				params: {
					login_account: '',
					password: ''
				},
				checked: false,
				navHeight: 0,
				radius:'50rpx',
				// show: true
			};
		},
		onShow() {
			this.navHeight = uni.getSystemInfoSync().windowTop
		},
		methods: {
			autoLogin() {
				if (Boolean(uni.getStorageSync("userpwd"))) {
					const userpwd = uni.getStorageSync("userpwd")
					this.params = JSON.parse(userpwd)
					this.login()
				}
			},
			// changeNav(){
			// 	uni.setNavigationBarColor({
			// 		frontColor: this.getTextColor.toLowerCase() === '#ffffff'? '#ffffff' : '#000000',
			// 	  backgroundColor: 'rgba(255, 255, 255, 1)'
			// 	})
			// },
			// 勾选同意 用户协议/隐私政策
			checkedCli() {
				if (!this.checked) {
					this.checked = true
				} else {
					this.checked = false
				}
			},
			// 登录
			login() {
				// 当前国际区号是否中国
				if (this.$store.state.areacode == 86) {
					if (!this.$u.test.mobile(this.params.login_account)) {
						this.$refs.uToast.show({
							// 请填写正确的手机号
							title: this.i18n.login15,
							type: 'error'
						});
						return false;
					}
				} else {
					if (!this.params.login_account) {
						this.$refs.uToast.show({
							// 请填写手机号
							title: this.i18n.login16,
							type: 'error'
						});
						return false;
					}
				}
				if (!this.params.password) {
					this.$refs.uToast.show({
						// 请填写密码
						title: this.i18n.login17,
						type: 'error'
					});
					return false;
				}
				if (!this.checked) {
					this.$refs.uToast.show({
						// 请勾选已阅读用户协议及隐私政策
						title: this.i18n.login18,
						type: 'error'
					});
					return false;
				}

				// 设置语言 1.中文 2.英文
				this.$store.commit('SetLang', '1');

				this.$u.api.login_make(this.params).then(res => {
					if (res.code == 200) {
						uni.setStorageSync('token', res.data.token);
						uni.setStorageSync('userpwd', JSON.stringify(this.params))
						uni.setStorageSync('usr', JSON.stringify({
							id: res.data.user.id,
							mobile: res.data.user.phone,
							name: res.data.user.nickname,
							avatar: res.data.user.avatar,
						}))
						this.changeAccount({
							id: res.data.user.id,
							mobile: res.data.user.phone,
							name: res.data.user.nickname,
							avatar: res.data.user.avatar,
							password: this.params.password,
						})
						uni.setStorageSync('id', res.data.user.id)
						setTimeout(() => {    //后加得，本身在下面
							uni.switchTab({
								url: '../../tabbar/home/home'
							})
						}, 1000)
						this.getImToken()
					}
				})
			},
			getImToken(){
				this.$u.api.imToken({
					platform: 5
				}).then(res=>{
					uni.setStorageSync('openImToken',res.data.info.token)
					uni.setStorageSync('openImUserid',res.data.info.userID)
					this.$refs.uToast.show({
						title: this.i18n.login19,
						type: 'success',
						duration: 1000,
					});
					setTimeout(() => {
						uni.switchTab({
							url: '../../tabbar/home/home'
						})
					}, 1000)
					this.$im.initIm()
				})
			},
			// 微博登录
			weiboLogin() {
				// uni.request({
				// 	url:'https://api.weibo.com/oauth2/authorize',
				// 	data:{
				// 		'client_id':'1500590007',
				// 		'redirect_uri': uni.$myAppConfig.baseUrl,
				// 	},
				// 	success(res) {
				// 		console.log(res)
				// 	},
				// 	fail(err) {
				// 		console.log(err)
				// 	}
				// })
				let url =
					`https://api.weibo.com/oauth2/authorize?client_id=1500590007&response_type=code&redirect_uri=${uni.$myAppConfig.baseUrl}/wap`;
				window.location.href = url
			}

		}
	}
</script>

<style lang="scss" scoped>
	
	.page{
		height: 100vh;
	}
	
	.box {
		padding-bottom: 20rpx;
	}

	.title {
		font-size: 30rpx;
		color: #9E9089;
		padding: 54rpx 0 0 64rpx;
	}
	.Head_image{
		width: 140rpx;
		height: 140rpx;
		margin: 0 auto;
		margin-top: 190rpx;
		background: #FFFFFF;
		border: 1rpx solid #707070;
		border-radius: 50%;
	}
	.title_h1 {
		width: fit-content;
		font-size: 42rpx;
		color: #fff;
		font-weight: bold;
		margin: 32rpx auto 119rpx;
	}

	.u_input {
		// margin: 48rpx 52rpx 0;
		background: #1E1E1E;
		padding: 0rpx 20rpx 0rpx 0rpx !important;
		border-radius: 50rpx;
	}

	.u_input1 {
		margin-top: 0;
		border: none;
		padding: 0 20rpx 0 0rpx !important;
	}

	.fun_flex {
		display: flex;
		justify-content: space-between;
		margin: 36rpx 76rpx 112rpx;
		// color: #764E39;
		font-size: 26rpx;
	}
	.input_num {
		margin: 48rpx 52rpx 0 52rpx;
		height: 88rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #1E1E1E;
		border-radius: 50rpx;
		// border-radius: 10rpx;
		text-indent: 34rpx;
		// border: 1px solid;
		.iconsjh{
			width: 40rpx;
			height: 40rpx;
			display: block;
			margin-left: 48rpx;
		}
	}

	.forget_pwd {
		text-align: right;
		margin-right: 80rpx;
		margin-top: 20rpx;
	}

	.authorize_title {
		display: flex;
		justify-content: center;
		// color: #666666;
		font-size: 24rpx;
		margin-top: 86rpx;
		align-items: center;

		.line {
			width: 54rpx;
			height: 2rpx;
			margin: 0 24rpx;
		}

		// .line_left {
		// 	background: linear-gradient(-90deg, #E6BB81 0%, #FFFFFF 100%);
		// }

		// .line_right {
		// 	background: linear-gradient(90deg, #E6BB81 0%, #FFFFFF 100%);
		// }
	}

	.weibo_login {
		text-align: center;
		margin: 68rpx;

		.weibo_img {
			width: 90rpx;
			height: 90rpx;
		}

		.weibo_text {
			font-size: 24rpx;
			// color: #333333;
			margin-top: 28rpx;
		}
	}

	.footer_protocol {
		display: flex;
		justify-content: center;
		align-items: center;

		image {
			width: 30rpx;
			height: 30rpx !important;
			margin-right: 30rpx;
			border: 1rpx solid #CAFD5C;
			border-radius: 50%;
			background-size: 100% 100%;
		}

		.color_ash {
			// color: #999999;
		}

		.color_black {
			// color: #333333;
		}
	}
</style>
